<?php
//彩种管理
namespace app\admin\controller;
use app\common\model\Code;
use think\Db;
use app\common\model\Document;
use app\common\controller\Payment;
use app\common\model\HuiYuanSupervise;
use GuzzleHttp\json_encode;
use think\Exception;

class Lottery extends Base
{
	private $code;
	public function _initialize()
	{
		parent::_initialize();
		$this->code = new Code();
		$this->member_model= new HuiYuanSupervise();
	}
	
	/**
	 * 彩票列表
	 * @return \think\mixed
	 */
	public function cz_list(){
		
	    $list = $this->code->Codelist('id asc');
	    $this->assign('list',$list);
	    $this->assign('page',input('page'));
	    return $this->fetch();
	}
	
	
	/**
	 * 修改彩票显示
	 * @param unknown $id
	 */
	public function cz_status($id){
	    $find = $this->code->CodeFind(array('id'=>$id));
	    if(input('get.dat') == 'mb'){
	        if($find['cp_mb_index'] == 1) {
	            $this->code->EditCode($id,array('cp_mb_index'=>0));
	            $this->member_model->caozuorizhi_xieru("设置“".$find['cp_name_old']."”的手机热门推荐状态为:否");
	        } else {
	            $this->code->EditCode($id,array('cp_mb_index'=>1));
	            $this->member_model->caozuorizhi_xieru("设置“".$find['cp_name_old']."”的手机热门推荐状态为:是");
	        }
	    }else if(input('get.dat') == 'dn'){
	        if($find['cp_dn_index'] == 1) {
	            $this->code->EditCode($id,array('cp_dn_index'=>0));
	            $this->member_model->caozuorizhi_xieru("设置“".$find['cp_name_old']."”的电脑热门推荐状态为:否");
	        } else {
	            $this->code->EditCode($id,array('cp_dn_index'=>1));
	            $this->member_model->caozuorizhi_xieru("设置“".$find['cp_name_old']."”的电脑热门推荐状态为:是");
	        }
	    }else if(input('get.dat') == 'open'){
	        if($find['cp_if_open'] == 1) {
    	        $this->code->EditCode($id,array('cp_if_open'=>0));
    	        $this->member_model->caozuorizhi_xieru("设置“".$find['cp_name_old']."”的彩票开关状态为:开");
    	    } else {
    	        $this->code->EditCode($id,array('cp_if_open'=>1));
    	        $this->member_model->caozuorizhi_xieru("设置“".$find['cp_name_old']."”的彩票开关状态为:关");
	        }
	    }
	    
	    $this->redirect("/admin/Lottery/cz_list?page=".input('page'));
	}
	
	
	/**
	 * 彩票排序
	 */
	public function cz_yhpx(){
	    $list = $this->code->Codelist('id asc');
	    foreach ($list as $val){
	        $value = array(
	            'cp_name_new'=>input('post.cp_name_new_'.$val['id']),
	            'cp_fp_time'=>input('post.cp_fp_time_'.$val['id']),
	        	'remark'=>input('post.remark_'.$val['id']),
	            'cp_mb_px'=>input('post.cp_mb_px_'.$val['id']),
	            'cp_dn_px'=>input('post.cp_dn_px_'.$val['id']),
	            'cp_mb_index'=>input('post.cp_mb_index_'.$val['id']),
	            'cp_dn_index'=>input('post.cp_dn_index_'.$val['id']),
	        );
	        $this->code->EditCode($val['id'], $value);
	    }
	    $this->redirect('/admin/lottery/cz_list');
	
	}
	
	/**
	 * 更新彩票信息
	 */
	public function updateCpInfo() {
	    $name = input('post.name') ? input('post.name') : '';
	    $value = input('post.value') ? input('post.value') : '';
	    if(!$name) {
	        return 0;
	    }

	    $key = substr($name,0,strrpos($name,'_'));
        $id = substr($name,strrpos($name,'_')+1);
        $result=Db::name('caipai_list')->where('id',$id)->find();
	    $res = $this->code->EditCode($id,array($key=>$value));
	    if($res === 1) {
	    	if($key=='cp_name_new'){
	    		$this->member_model->caozuorizhi_xieru("设置“".$result['cp_name_old']."”的自定义名字为:".$value);
	    	}
	    	if($key=='remark'){
	    		$this->member_model->caozuorizhi_xieru("设置“".$result['cp_name_old']."”的备注为:".$value);
	    	}
	    	if($key=='num_day'){
	    		$this->member_model->caozuorizhi_xieru("设置“".$result['cp_name_old']."”的彩票期数为:".$value);
	    	}
	    	if($key=='cp_fp_time'){
	    		$this->member_model->caozuorizhi_xieru("设置“".$result['cp_name_old']."”的封盘时间为:".$value);
	    	}
	    	if($key=='cp_mb_px'){
	    		$this->member_model->caozuorizhi_xieru("设置“".$result['cp_name_old']."”的手机排序为:".$value);
	    	}
	    	if($key=='cp_dn_px'){
	    		$this->member_model->caozuorizhi_xieru("设置“".$result['cp_name_old']."”的电脑排序为:".$value);
	    	}
	        return 1;
	    } else {
	        return 0;
	    }
	}
	public function updateCpTimeInfo(){
		$name = input('post.name') ? input('post.name') : '';
	    $value = input('post.value') ? input('post.value') : '';
	    if(!$name || !$value) {
	        return 0;
	    }

        $id = substr($name,strrpos($name,'_')+1);
		$result = Db::name('time')->alias('t')->join('__CAIPAI_LIST__ cl','cl.id=t.czid')->field('cl.cp_name_old')->where('t.id',$id)->find();
		$res = Db::name('time')->where('id',$id)->update(array('jztime'=>$value));
		if($res===1){
			$this->member_model->caozuorizhi_xieru("设置彩种“".$result['cp_name_old']."”的ID为“".$id."”的时间为".$value);
			return 1;
		} else{
			return 0;
		}
	}
	
	/**
	 * 赔率列表
	 * @param unknown $lid
	 * @return \think\mixed
	 */
	public function cz_plsz(){
	    $id = input('get.id');
		$method = input('get.method',0);
		if( 0==$method ){
			$caizhong = Db::name('lottery_classify')->field('id,class_name_lottery')->where('status',1)->select();
			if(empty($id) || !isset($id)){
				$id = $caizhong[0]['id'];
			}
			$CZNAME = $this->code->CodeFind(array('id'=>$id));
			$CZNAME = $CZNAME['cp_name_new'] == '' ? $CZNAME['cp_name_old'] : $CZNAME['cp_name_new'];
			$pl_str = Db::name('play_classify_ext')->alias('a')
					->join('kkty_play_classify b','a.play_id=b.id','LEFT')
					->value('group_concat(a.peilv_ids)');
			$list = $this->code->PeilvAll(array('lottery_class_id'=>$id,'ifopen'=>1,'id'=>['not in',$pl_str]));
			foreach($list as &$v) {
				if($v['spare']) $v['peilv_name'] = $v['spare'].'_'.$v['peilv_name'];
			}
		}else{
			$caizhong = Db::name('caipai_list')->field('id,cp_name_old as class_name_lottery')->select();
			if(empty($id) || !isset($id)){
				$id = $caizhong[0]['id'];
			}
			$CZNAME = Db::name('caipai_list')->where(['id'=>$id])->value('cp_name_old');
			$pl_str = Db::name('play_classify_ext')->alias('a')
					->join('kkty_play_classify b','a.play_id=b.id','LEFT')
					->where(['a.czid'=>$id])
					->value('group_concat(a.peilv_ids)');
			$list = Db::name('peilv')->where('id','in',$pl_str)->select();
			foreach($list as &$v) {
				if($v['spare']) $v['peilv_name'] = $v['spare'].'_'.$v['peilv_name'];
			}
			unset($v);
		}
		$this->assign('CZNAME',$CZNAME);
	    $this->assign('list',$list);
	    $this->assign('method',$method);
	    $this->assign('caizhong',$caizhong);
	    return $this->fetch();
	}


	/**
	 * 彩种玩法列表
	 * @param unknown $lid
	 * @return \think\mixed
	 */
	public function cz_wfsz(){
	    $id = input('get.id');
	    $caizhong = $this->code->CodeAll(array('cp_if_open'=>1));
	    if(empty($id) || !isset($id)){
	        $id = $caizhong[0]['id'];
	    }
	    $CZNAME = $this->code->CodeFind(array('id'=>$id));
	    $CZNAME = $CZNAME['cp_name_new'] == '' ? $CZNAME['cp_name_old'] : $CZNAME['cp_name_new'];
	    $this->assign('CZNAME',$CZNAME);

//	    $list = $this->code->playFunc(array('czid'=>$id));
		$czids = Db::name('lottery_classify')->where("czids REGEXP '(^|,){$id}($|,)'")->value('czids');
		$list = Db::name("play_func")->where('czid','in',explode(',',$czids))->select();

		$this->assign('list',$list);
	    $this->assign('caizhong',$caizhong);
	    return $this->fetch();
	}


	/**
	 * 开奖数据
	 * @param 【分类id】 $lid
	 * @return \think\mixed
	 */
	public function cz_kjjg(){
		$limit=input('get.limit')?input('get.limit'):20;
		$this->assign('limit',$limit);
	    $id = input('get.id');
	    $qihao = input('qihao');
	    $stua = input('stua');
	    $this->assign('stua',$stua);
	    $caizhong = $this->code->CodeAll(array('cp_if_open'=>1));
	    if(empty($id) || !isset($id)){
	        $id = $caizhong[0]['id'];
	    }
	    $CZNAME = $this->code->CodeFind(array('id'=>$id));
	    $CZNAMES = $CZNAME['cp_name_new'] == '' ? $CZNAME['cp_name_old'] : $CZNAME['cp_name_new'];
	    $this->assign('CZNAME',$CZNAMES);
	    $this->assign('czid',$id);
	    $where['czid']=$id;
	    if( !empty($qihao) ){
	    	$where['qihao']=$qihao;
	    }
	    if($stua==1){
	    	$where['kjjg']=0;
	    	$where['jztime']=['<',time()];
	    }
	    $list = $this->code->KjjgList('id desc',$where,$limit);
	    foreach ($list as &$val){
	        $touzhu = $this->code->TouzhuAll(array('czid'=>$val['czid'],'qihao'=>$val['qihao']));
	        $ZTZJE = 0;
	        foreach ($touzhu as $dat){
	            $ZTZJE=$ZTZJE+$dat['tzje'];
	        }
	        
	        $val['kjjg'] = kjjg_split($val['kjjg'], $val['czid']);

	        if($ZTZJE<0.001)$ZTZJE=0;
	        $val['touzhu'] = $ZTZJE;
	    }
	    $this->assign('id',$id);
	    $this->assign('list',$list);
	    $this->assign('qihao',$qihao);
	    $this->assign('caizhong',$caizhong);
	    return $this->fetch();
	}
	public function jiesuan(){
		$payment = new Payment();
		$payment->index();
		$czid = input('get.czid');
	    $qihao = input('get.qihao');
	    $ssclist = Db::name('caipai_list')->where(array('id'=>$czid))->find();
		$this->member_model->caozuorizhi_xieru("手动结算【".$ssclist['cp_name_old']."】第:【".$qihao."】期");
		alert_back('成功');
	}
	public function cz_kjth(){

	    $czid = input('get.czid');
	    $qihao = input('get.qihao');
	    if($czid != '' && $qihao != ''){
	        $thcxss = $this->code->CodejgFind(array('czid'=>$czid,'qihao'=>$qihao));
	        if($thcxss['jztime']<time() && $thcxss['iftz']<1){
	            $tkopen = Db::name('touzhu_list_no')->where(array('czid'=>$czid,'qihao'=>$qihao))->select();
    	        Db::startTrans();
    	        try{
    	        	
        	        foreach ($tkopen as $val){
        	        	$je = Db::name('username')->where('username',$val['username'])->value('je');
        	        	$val['tkqje']=$je;
        	        	unset($val['rktime']);
        	        	$val['tktime']=time();
        	        	 
        	        	Db::name('touzhu_list_tk')->insert($val);
        	        	Db::name('touzhu_list_no')->where('id',$val['id'])->delete();
        	            //$document->EditDocument('username', array('username'=>$val['username']), array('je'=>['exp',"je+{$val['tzje']}"]));
        	            Db::name('username')->where('username',$val['username'])->setInc('je',$val['tzje']);
        	            
         	            $ssclist = Db::name('caipai_list')->where(array('id'=>$czid))->find();
        	            if($ssclist['cp_name_new']==''){
        	                $ssclist=$ssclist['cp_name_old'];
        	            }else{
        	                $ssclist=$ssclist['cp_name_new'];
        	            }
        	            $data = array(
        	                'username'=>$val['username'],
        	                'test'=>"您投注的彩种：【".$ssclist."】第：【".$qihao."】未开奖，系统退还本金：【".$val['tzje']."】元！",
        	                'xx_time'=>time(),
        	                'ifdq'=>0
        	            );

        	            $this->code->AddXiaoxi($data);

        	        }
        	        $this->code->EditCodekj($czid, $qihao, array('iftz'=>2));
        	        Db::commit();
        	        $ssclist = Db::name('caipai_list')->where(array('id'=>$czid))->find();
        	        $this->member_model->caozuorizhi_xieru("【".$ssclist['cp_name_old']."】第：【".$qihao."】未开奖，退还本金");
        	        js_tishi('成功', '/admin/lottery/cz_kjjg?id='.$czid);
    	        }catch (\Exception $e) {
                    // 回滚事务
                    Db::rollback();
                    alert_back('错误');
               }
               
	        }
	    }
	    
	}
	
	
	public function cz_sgkjcx(){
	    $find = $this->code->CodejgFind(array('id'=>input('get.id')));
	    return $find['qihao'];
	}
	public function cz_cxkj(){
		$kjjg = input('kjjg');
	    $czid = input('czid');
	    $qihao = input('qihao');
	    $kjjg = explode(',', $kjjg);
	    $kjjg = implode('', $kjjg);
	    $kj = Db::name('kjjg_list')->where(['czid'=>$czid,'qihao'=>$qihao])->find();
	    $touzhu = Db::name('touzhu_list_ok')->where(['czid'=>$czid,'qihao'=>$qihao])->whereTime('tz_time','today')->select();
	    if(isset($touzhu[0])){
		    foreach($touzhu as $tz){
		    	Db::name('touzhu_list_cc')->data($tz)->insert();
		    	if($tz['zjje']>0){
		    		Db::name('username')->where('username',$tz['username'])->update(array('je'=>['exp',"je-'{$tz['zjje']}'"],'zjje'=>['exp',"zjje-'{$tz['zjje']}'"]));
				}
		    	unset($tz['status'],$tz['fs'],$tz['rktime'],$tz['zjje'],$tz['ifqs']);
		    	Db::name('touzhu_list_no')->data($tz)->insert();
		    }
		    if(Db::name('kjjg_list')->where(['id'=>$kj['id']])->update(array('kjjg'=>$kjjg))){
		    	return 1;
		    }else{
		    	return '重新开奖失败';exit;
		    }
	    }else{
	    	return '只可重新开启当天的开奖结果';exit;
	    }		
	}
	
	public function cz_sgkj(){
	    $kjjg = input('kjjg');
	    $czid = input('czid');
	    $qihao = input('qihao');
	    $kjjg = explode(',', $kjjg);
	    $kjjg = implode('', $kjjg);
	    //if(is_numeric($kjjg)==1){
	        $xckj = $this->code->CodejgFind(array('qihao'=>$qihao,'czid'=>$czid));
	        if($xckj['kjjg']<1){
	           
	                if($xckj['jztime']<time()){
	                	if(Db::name('kjjg_list')->where('czid',$czid)->where('qihao',$qihao)->update(array('kjjg'=>$kjjg,'iftz'=>1))){
	                		$ssclist = Db::name('caipai_list')->where(array('id'=>$czid))->find();
	                		$this->member_model->caozuorizhi_xieru("【".$ssclist['cp_name_old']."】第:【".$qihao."】期，手动开奖");
	                    	return 1;
	                    }else{
	                    	return '手动添加失败';exit;
	                    }
	                }else{
	                    return '本期尚未结束投注，不能进行手工开奖！';exit;
	                }
	            
	        }else{
	            return '已开奖，不能手工开奖';exit;
	        }
	   /*  }else{
	        return '开奖号码必须为数字！';exit;
	    } */
	}

	
	public function cz_kjsj(){
	    $id = input('get.id');
	    $caizhong = $this->code->CodeAll();
	    if(empty($id) || !isset($id)){
	        $id = $caizhong[0]['id'];
	    }
	    $CZNAME = $this->code->CodeFind(array('id'=>$id));
	    $CZNAME = $CZNAME['cp_name_new'] == '' ? $CZNAME['cp_name_old'] : $CZNAME['cp_name_new'];
	    $lhc = Db::name('kjjg_list')->where(['czid'=>9,'kjjg'=>0,'jztime'=>['>',time()]])->limit(1)->order('qihao','ASC')->find();
	    $this->assign('time',date('Y-m-d',$lhc['jztime']));
	    $this->assign('lhc',$lhc);
	    $this->assign('CZNAME',$CZNAME);
	    $list = $this->code->CodeTimeAll(array('czid'=>$id));
	    $this->assign('list',$list);
	    $this->assign('caizhong',$caizhong);
	    return $this->fetch();
	}
	
	/**
	 * 限额设置
	 */
	public function money_limit(){
	    $list = $this->code->playClassify();
	    $this->assign('list',$list);
	    return $this->fetch();
	}
	
	/**
	 * 限额修改
	 */
    public function updateMlInfo() {
	    $id = input('post.name') ? input('post.name') : '';
	    $value = input('post.value') ? input('post.value') : '0';

	    if(!$id) {
	        return 0;
	    }
	    $result=Db::name('play_classify')->where('id',$id)->find();
	    $res = $this->code->EditMoneyLimit($id,array('max_money'=>$value));
	    if($res === 1) {
	    	$this->member_model->caozuorizhi_xieru("设置“".$result['class_name_mini']."”的最高单注投注金额为".$value);
	        return 1;
	    } else {
	        return 0;
	    }
	}
	/**
	 * 六合彩特码A返点设置
	 */
	public function lhcReturnPoint(){
		if(input('post.')){
			$fandian = input('post.fandian');
			$zmfd = input('post.zmfd');
			if($fandian==''){alert_back('返点不能为空');}
			$fd = Db::name('lhc_fd')->where('id',1)->find();
			if($fd){
				$sure = Db::name('lhc_fd')->where('id',1)->update(array('fandian'=>$fandian,'zmfd'=>$zmfd));
			}else{
				$sure = Db::name('lhc_fd')->insert(array('id'=>1,'fandian'=>$fandian,'zmfd'=>$zmfd));
			}
			if($sure){
				$this->member_model->caozuorizhi_xieru('设置六合彩的返点，特码A返点:'.$fandian."%，正码A返点:".$zmfd."%");
				js_tishi('设置成功', 'lhcReturnPoint');
			}else{
				alert_back('设置失败');
			}
		}else{
			$fand = Db::name('lhc_fd')->where('id',1)->find();
			
			$this->assign('fand',$fand);
			return $this->fetch('lhc_return');
		}
	}
	public function lhcTimeSave(){
		$lhc = Db::name('kjjg_list')->field('id,jztime,qihao')->where(['czid'=>9,'kjjg'=>0,'jztime'=>['>',time()]])->limit(1)->order('qihao','ASC')->find();
		$time = input('post.time');
		$id = input('post.id');
		if(date('Y-m-d',$lhc['jztime'])!=$time){
			if(Db::name('kjjg_list')->where(['id'=>$id,'czid'=>9])->update(array('jztime'=>strtotime($time.' 21:29:45')))){
				return 1;
			}else{
				return 0;
			}
		}else{
			return 2;
		}
	}
	
	/**
	 * 赔率修改
	 */
	public function updatePlInfo() {
	    $sign = input('post.name') ? input('post.name') : '';
	    $value = input('post.value') ? input('post.value') : '';
	    if(!$sign) {
	        return 0;
	    }
	    $sign = explode('_', $sign);
	    $name = $sign[0];
	    $id = $sign[1];
	    $result=Db::name('peilv')->where('id',$id)->find();
	    $res = $this->code->EditCodePl($id,array($name=>$value,'zdpl'=>$value));
	    if($res === 1) {
	    	if($name=="zgpl"){
	    		$this->member_model->caozuorizhi_xieru('设置:'.$result['peilv_name']."的最高赔率为:".$value);
	    	}
	    	if($name=="zdpl"){
	    		$this->member_model->caozuorizhi_xieru('设置:'.$result['peilv_name']."的最低赔率为:".$value);
	    	}
	        return 1;
	    } else {
	        return 0;
	    }
	}
	
	/**
	 * 玩法修改
	 */
	public function updateWfInfo() {
	    $id = input('post.name') ? input('post.name') : '';
	    $value = input('post.value') ? input('post.value') : '';
	    if(!$id) {
	        return 0;
	    }
	    $result=Db::name('play_func')->where('id',$id)->find();
	    $res = $this->code->EditCodeWf($id,array('func_desc'=>$value));
	    if($res === 1) {
	    	$this->member_model->caozuorizhi_xieru("修改“".$result['func_name']."”的玩法介绍");
	        return 1;
	    } else {
	        return 0;
	    }
	}
	/**
	 * 清除分分彩开奖结果
	 */
	public function delFfcKjjg(){
		$startTime = strtotime(date('Y-m-d H:i:s',strtotime('-10 day')));
		$query = Db::name('kjjg_list')->where('jztime','<',$startTime)->where('czid','62')->where('kjjg','>','0')->delete();
		if($query){
			echo '清除成功';
		}else{
			echo '清除失败';
		}
		
	}
	public function category(){
		$list = Db::name("lottery_classify")->field("id,czids,class_name_lottery,class_sign,fandian,status,sorting")->select();
		$lottery = Db::name("caipai_list")->column("id,cp_name_old,cp_name_new");
		foreach( $list as &$v ){
			$czid_attr = explode(',',trim($v['czids']));
			$v['lottery'] = [];
			foreach($czid_attr as $val){
				if( isset($lottery[$val]) ){
					$v['lottery'][] = empty($lottery[$val]['cp_name_new']) ? $lottery[$val]['cp_name_old'] : $lottery[$val]['cp_name_new'];
				}
			}
			$v['lottery'] = implode(',',$v['lottery']);
		}
		unset($v);
		$this->assign('list',$list);
		return $this->fetch();
	}
	public function changeCategoryStatus(){
		$id = input('id',0);
		if($id){
			$result=Db::name('lottery_classify')->where('id',$id)->find();
		}
		$change = input('change',0);
		if($change==1){
			$zhuangtai="开";
		}
		if($change==0){
			$zhuangtai="关";
		}
		if(Db::name("lottery_classify")->where(['id'=>$id])->update(['status'=>$change])){
			$this->member_model->caozuorizhi_xieru('设置账户:'.$result['class_name_lottery']."的状态为".$zhuangtai);
			return 1;
		}else{
			return 0;
		}
	}
	public function changeCategorySort(){
		$id = input('id',0);
		if($id){
			$result=Db::name('lottery_classify')->where('id',$id)->find();
		}
		$sort = input('sort',0);
		if(Db::name("lottery_classify")->where(['id'=>$id])->update(['sorting'=>$sort])){
			$this->member_model->caozuorizhi_xieru('设置账户:'.$result['class_name_lottery']."的顺序为".$sort);
			return 1;
		}else{
			return 0;
		}
	}
	public function asyncInfo(){
		$id = input('id',0);

		$class = Db::name('lottery_classify')->where("czids REGEXP '(^|,){$id}($|,)'")->value('id');
		$ext = Db::name('play_classify_ext')->where(['czid'=>$id])->select();
		$play_way = Db::name('play_classify')->alias('a')
					->join('kkty_way_classify b','a.way_class_id=b.id','LEFT')
					->where("b.lottery_class_id={$class}")
					->column('a.id,a.peilv_ids');
		$bind = [];
		Db::startTrans();
		try{
			if( empty($ext) ){
				foreach( $play_way as $k=>$v ){
					$v = explode(',',trim($v));
					$id_attr = [];
					foreach($v as $val){
						$pl = Db::name('peilv')->find($val);
						if( !empty($pl) ){
							$oldid = $pl['id'];
							unset($pl['id']);
							if( in_array($oldid,array_keys($bind)) ){
								$newid = $bind[$oldid];
							}else{
								if( !$newid = Db::name('peilv')->insertGetId($pl) ){
									throw new Exception('error');
								}
								$bind[$oldid] = $newid;
							}
							$id_attr[] = $newid;
						}
					}
					if( !Db::name('play_classify_ext')->data(['play_id'=>$k,'czid'=>$id,'peilv_ids'=>implode(',',$id_attr)])->insert() ){
						throw new Exception('error');
					}
				}
				Db::commit();
				return 1;
			}else{
				foreach( $ext as $v ){
					$ext_pl = explode(',',trim($v['peilv_ids']));
					$way = Db::name('play_classify')->find($v['play_id']);
					$basis_pl = explode(',',trim($way['peilv_ids']));
					foreach($basis_pl as $key=>$val){
						$pl = Db::name('peilv')->find($val);
						Db::name('peilv')->where(['id'=>$ext_pl[$key]])->update(['zgpl'=>$pl['zgpl'],'zdpl'=>$pl['zdpl']]);
					}
				}
				Db::commit();
				return 1;
			}
		}catch (Exception $e){
			Db::rollback();
			return 0;
		}
	}
}